import 'package:flutter/material.dart';

import 'package:charts_flutter/flutter.dart' as charts;
import 'package:drm/base/tj_date_entity.dart';
import 'package:drm/util/utils.dart';
class OnePage extends StatefulWidget {
  List<TjDateEntity> data;
  String unit;
  OnePage({Key key ,this.data,this.unit}):super(key:key) ;
  @override
  _OnePageState createState() => _OnePageState();
}

class _OnePageState extends State<OnePage> {
  @override
  Widget build(BuildContext context) {
    return charts.BarChart(
      _createSampleData(),
      animate: true,
      vertical: false,
      barRendererDecorator: new charts.BarLabelDecorator<String>(),
//      behaviors: [new charts.SeriesLegend(
//        position: charts.BehaviorPosition.top,
//
//      )],
    );
  }
   List<charts.Series<TjDateEntity, String>> _createSampleData() {
    return [
      new charts.Series<TjDateEntity, String>(
        id: '销售额',
        domainFn: (TjDateEntity sales, _) => MyUtils.getChartLeftTitle(sales.name),
        measureFn: (TjDateEntity sales, _){
          try {
            return double.parse(sales.value);
          }
          catch(e) {
            return 0 ;
          }
        },
        data: widget.data,
        labelAccessorFn: (TjDateEntity sales, _) {
          if ( widget.unit == '元') {
            return ' ${MyUtils.numFormat(sales.value)}';
          }else {
            return '${sales.value}';
          }

        }

      ),
    ];
  }
}

